'''
Created on Mar 17, 2013

@author: kevinbauer
'''
import numpy as np

class ResultAnalysis():

    def __init__(self):
        pass
   
    def compareResult(self,resultData):
        '''
        in the two column array resultData , 
        value 0 means is normal connection
        the first column is real value of this row, 
        the second column is the result of algorithm detected
        '''
        noCorrect = 0
        for rowValue in resultData:
            if rowValue[0]==rowValue[1]:
                 noCorrect = noCorrect
            else:
                noCorrect = noCorrect + 1
        
        amount =  resultData.shape[0]  
        errorRate =  np.true_divide(noCorrect, amount)
        
        print "---------------------------------------------"     
        print "test " , amount , " line record"
        print "not correct amount is :" , noCorrect
        print "the error percent is:" ,errorRate


    def compareResultKappa(self,resultData):
        ''' Kappa Statistics
        '''
        '''
        in the two column array resultData , 
        value 0 means is normal connection
        the first column is real value of this row, 
        the second column is the result of algorithm detected
        '''
        FPAmount = 0
        FNAmount = 0
        TPAmount = 0
        TNAmount = 0
        errAmount = 0
        for rowValue in resultData:
            if rowValue[0] == rowValue[1]:
                 if rowValue[0] == 0:
                     TPAmount = TPAmount + 1
                 else:
                     TNAmount = TNAmount + 1
            else:
                 errAmount = errAmount + 1
                 if rowValue[0] == 0:
                     FPAmount = FPAmount + 1
                 else:
                     FNAmount = FNAmount + 1
        
        totalAmount =  resultData.shape[0]  
        errRate =  np.true_divide(errAmount, totalAmount)   
                  
        print "compare " , totalAmount , " line"
        print "not correct number is :" , errAmount
        print "the error percent is:" ,errRate
        
        print "FP percent is :" , errAmount
        print "the error percent is:" ,errRate        
                 
        
        
    
